home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $AddLineNumbers next >
Encoding:
Text File  |  1991-10-28  |  708 b   |  25 lines  |  [TEXT/KEEN]

  1. #$AddLineNumbers
  2. #Intended for use on one specific file at a time - 
  3. #use the "Select input file..." option under the "Take input from:" popup
  4. #to select the file to be numbered.
  5.  
  6. BEGIN { outfile = ARGV[1]; }#remember the input file name
  7.  
  8. #collect numbered lines in an array, justifying line numbers
  9.     {     if (NF == 0 || (NF == 1 && $1 == " "))#that's an option-space there
  10.             out[NR] = $0;
  11.         else if (NR >= 1000)
  12.             out[NR] = NR "\t" $0;
  13.         else if (NR >= 100)
  14.             out[NR] = " " NR "\t" $0;
  15.         else if (NR >= 10)
  16.             out[NR] = "  " NR "\t" $0;
  17.         else
  18.             out[NR] = "   " NR "\t" $0;
  19.     }
  20.  
  21. END {     close(outfile);#a nice touch when switching from read to write
  22.         for (i = 1; i <= NR; ++i)
  23.             print out[i] > outfile
  24.     }
  25.